// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui';
import storeConfig from '../store/store'
import VueScrollReveal from 'vue-scroll-reveal';
import 'element-ui/lib/theme-chalk/index.css';
import 'element-ui/lib/theme-chalk/display.css';
import VueI18n from 'vue-i18n'
import routes from './router/index'
import 'animate.css'
import './assets/iconfont/iconfont.css'
//import 'font-awesome/css/font-awesome.css'
import './assets/style/style.styl'
import APlayer from '@moefe/vue-aplayer';
import axios from 'axios'
import VueAxios from 'vue-axios'
import qs from 'qs'
import vuex from 'vuex'
import store from '../store/index'
import querystring from 'querystring'
Vue.prototype.$qs= querystring;
Vue.use(VueAxios,axios)
Vue.prototype.$axios= axios
// axios.interceptors.request.use(config => {
//   //请求头对象，添加TOKEN验证的Authorization字段
//   config.headers.Authorization = window.sessionStorage.getItem('token')
//   return config
// })

// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.post['Content-Type'] = 'multipart/formdata';
axios.interceptors.request.use(config => {
   console.log(config)
   config.headers.Authorization = 'Bearer '+ localStorage.getItem('token')
   return config
 })

// axios.interceptors.request.use(function(config) {
//   if(localStorage.getItem('token')) {
//     config.headers.commom['token'] = localStorage.getItem('token')
//   }
//   return config;
// },function(error) {
//   return Promise.reject(error)
// })

// axios.interceptors.request.use(
//   config => {
//    if (localStorage.getItem('Authorization')) {
//         config.headers.Authorizatior = localStorage.getItem('Authorization');
//       }
    
//     return config;
//   },
//   error => {
//     return Promise.reject(error);
//   });
// //异步请求后，判断token是否过期
// axios.interceptors.response.use(
//   response =>{
//     return response;
//   },
//   error => {
//     if(error.response){
//       switch (error.response.status) {
//         case 401:
//           localStorage.removeItem('token');
//           this.$router.push('/');
//       }
//     }
//   }
// )
//异步请求前判断请求的连接是否需要token
// router.beforeEach((to, from, next) => {
//   if (to.path === '/') {
//     next();
//   } else {
//     let token = localStorage.getItem('Authorization');
//     console.log("我是浏览器本地缓存的token: "+token);
//     if (token === 'null' || token === '') {
//       next('/');
//     } else {
//       next();
//     }
//   }
// });



// import mavonEditor from 'mavon-editor'
// import 'mavon-editor/dist/css/index.css'
// // use
// Vue.use(mavonEditor)
import hljs from 'highlight.js' //导入代码高亮文件
import 'highlight.js/styles/monokai-sublime.css'  //导入代码高亮样式
//自定义一个代码高亮指令
Vue.directive('highlight',function (el) {
  let highlight = el.querySelectorAll('pre code');
  highlight.forEach((block)=>{
      hljs.highlightBlock(block)
  })
})
// axios.defaults.baseURL="http://31f747b701.qicp.vip/"
// this.axios.defaults.baseURL="http://31f747b701.qicp.vip/"

axios.defaults.baseURL="http://31f747b701.qicp.vip/"
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
// axios.interceptors.request.use(config=>{
//   if(config.method='post'){
//     config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
//     // config.headers['Content-Type'] ="multipart/form-data"
  
//   }
//   return config
// })
// Vue.config.productionTip = false

Vue.use(VueScrollReveal, {
  class: 'scroll-item', // A CSS class applied to elements with the v-scroll-reveal directive; useful for animation overrides.
  duration: 1000,
  scale: 1,
  //distance: '10px',
  mobile: false
});


Vue.use(APlayer,{productionTip: false});
Vue.use(ElementUI);
Vue.use(VueI18n);
Vue.use(VueRouter)

const router =new VueRouter({
  linkActiveClass:'is-active',
	routes,
	mode: 'history'
})

const i18n = new VueI18n({
  locale: 'zh',
  messages:{
    'zh' : require('./lang/zh'),
    'en' : require('./lang/en')
  }
})

// window.onresize = setHtmlFontSize;
// function setHtmlFontSize(){
//     const htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
//     const htmlDom = document.getElementsByTagName('html')[0];
//     htmlDom.style.fontSize = htmlWidth / 10 + 'px';
// };
// setHtmlFontSize();


/* eslint-disable no-new */
new Vue({
  router,
  store,
	i18n,
	render: h => h(App),
}).$mount('#app')
